/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package toolz;

import java.util.ArrayList;

/**
 *
 * @author bunkowski
 */
public class MyMath {

    public static double round(double value,int precision){
        double precisionFull = Math.pow(10, precision);
        return Math.round(value * precisionFull) / precisionFull;
    }

    public static double discretize(double value,double discretize){
        return Math.round(value / discretize) * discretize;
    }


    public static void statisticValues(ArrayList<Double> values) {
        int n = values.size();
        Double R[] = new Double[n]; // erzeugt Platz fuer n Zahlen
        int i;

        values.toArray(R);

        // Mittelwert:
        double sum = 0;
        for (i = 0; i < n; i++) {
            sum += R[i]; // berechne Summe
        }
        double mean = sum / n;
        System.out.println("Mittelwert : " + mean);

        // Stichprobenabweichung:
        sum = 0;
        for (i = 0; i < n; i++) {
            sum += (mean - R[i]) * (mean - R[i]);
        }
        // berechne Varianz
        System.out.println("Standard-Abweichung : "
                + Math.sqrt(sum / (n - 1)));

        // Verteilung:
        int m = 10;
        int I[] = new int[m]; // Platz fuer m Zaehler
        int j;
        for (j = 0; j < m; j++) {
            I[j] = 0; // mit 0 initialisieren
        }
        for (i = 0; i < n; i++) // zaehlen
        {
            j = (int) Math.floor(R[i] * m);
            // in welchem Intervall liegt R[i]?
            if (j >= m) {
                j = m - 1; // falls R[i]==1.0
            }
            I[j]++; // erhoehe Zaehler
        }

        // Ausgabe:
        for (j = 0; j < m; j++) // Ausgabe der Zaehlungen
        {
            System.out.println((j + 1) + " : " + I[j]);
        }
    }
}
